package com.yunao.service.report.esou.Jfreechart;

import com.yunao.service.report.esou.ChartUtils;
import com.yunao.service.report.esou.Serie;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.block.BlockBorder;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.data.category.DefaultCategoryDataset;

import java.awt.*;
import java.util.Vector;


/**
 * 
 * @author 
 */
public class BarChart {
	public BarChart() {
	}

	public JFreeChart createChartBar(String title , String xName , String yName ,String row[] , String xAxis[] , Double data[][]) {
		JFreeChart chart = ChartFactory.createBarChart(title, xName , yName, createDataset( row , xAxis ,data));
		CategoryPlot plot = (CategoryPlot)chart.getCategoryPlot();
		plot.setOutlinePaint(Color.WHITE);
		ChartUtils.setBarRenderer(plot, false);
		ChartUtils.setXAixs(plot);
		ChartUtils.setYAixs(plot);
		//ChartUtils.setStackBarRender(chart.getCategoryPlot());
		chart.getLegend().setFrame(new BlockBorder(Color.WHITE));	
		return chart;
	}
	public JFreeChart createChartBar1(String title , String xName , String yName ,String row[] , String xAxis[] , Double data[][]) {
		JFreeChart chart = ChartFactory.createBarChart(title, xName , yName, createDataset( row , xAxis ,data));
		CategoryPlot plot = (CategoryPlot)chart.getCategoryPlot();
		plot.setOutlinePaint(Color.WHITE);
		ChartUtils.setBarRenderer1(plot, false);
		ChartUtils.setXAixs(plot);
		ChartUtils.setYAixs(plot);
		//ChartUtils.setStackBarRender(chart.getCategoryPlot());
		chart.getLegend().setFrame(new BlockBorder(Color.WHITE));	
		return chart;
	}
	
	public DefaultCategoryDataset createDataset(String row[] , String xAxis[] , Double data[][]) {
//		for (int i = 0; i < data.length; i++) {
//			for (int j = 0; j < data[i].length; j++) {
//				System.out.println("em:"+data[i][j]);
//			}
//		}
		Vector<Serie> series = new Vector<Serie>();
		for (int i = 0; i < row.length; i++) {
//			System.out.println(row[i]);
//			for (int j = 0; j < data[i].length; j++) {
//				System.out.println(row[i]+"-------------------"+data[i][j]);
//			}
			if(row[i] == null)
				break;
			System.out.println(data[i].length);
			series.add(new Serie(row[i], data[i]));
			
		}
		DefaultCategoryDataset dataset = ChartUtils.createDefaultCategoryDataset(series, xAxis);
		return dataset;
	}
}
